package net.zjitc.controller;

import net.zjitc.entity.Category;
import net.zjitc.service.CategoryService;
import net.zjitc.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 毛若颖
 * @date 2024/12/21 8:40
 */
@RestController
@RequestMapping("/admin/category")
@CrossOrigin
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/list")
    public Result getCategoryList(@RequestHeader String token){
        Result result=categoryService.getCategoryList();
        return result;
    }
    @GetMapping("/{id}")
    public Result getCategoryById(@RequestHeader String token,@PathVariable Integer id){
        return categoryService.getCategoryById(id);
    }
    @PostMapping("/add")
    public Result addCategory(@RequestHeader String token, @RequestBody Category category){
        return categoryService.addCategory(category);
    }
    @PostMapping("/save")
    public Result saveCategory(@RequestBody Category category,@RequestHeader String token){
        return categoryService.saveCategory(category);
    }
    @DeleteMapping("/del/{id}")
    public Result delCategory(@PathVariable Integer id,@RequestHeader String token){
        return categoryService.delCategory(id);
    }
}
